Undoable Change
UndoableChange uses the Moneydance sync system to record the before and after state of objects, providing an easy mechanism for undo-ing and redo-ing changes to a set of objects. To use, create an UndoableChange object, and record any deletions with finishDeletion(objectToDelete), creations with finishModification(newObject), and modifications with beginModification(object) before the object is changed and finishModification(object) after. Then record the change with the undo manager's recordChange(change).
Nothing reaches the data until the change is recorded: recordChange() calls redo(), which saves every item. Use finishModification() instead of syncItem() - never both.
finishDeletion() deletes only the given item. To delete a currency or security together with its prices and stock splits, use CurrencyType.deleteItem(change).
The order in which the items of one change are applied (on redo and undo) is not guaranteed, and only each item's final state is recorded. If the sequence or an item's intermediate states matter, use separate UndoableChanges.
Recording applies a copy of each item to the book, not the object you passed in. After recording, fetch items from the book again (e.g. by UUID) before using them.
Functions
Register the given object for an undo-able change and return the Change object that corresponds to it. The current state of the preModificationItem will be saved so that it can be restored if the change is undone.
Add the given item's deletion to this changeset, so that it can be undone after it is recorded. If the given item is a SplitTxn then it is recorded as a removal from the parent and a modification of the parent transaction. Only the given item is deleted: for a currency or security with prices and stock splits, use CurrencyType.deleteItem(change) instead.
Add the given item's modification to this changeset, so that it can be undone after the changeset is recorded. Before calling finishModification, the caller should have invoked beginModification() with the same object as a parameter so that the "before" state of the object can be known. If the item hadn't previously been saved (synced) then this is treated as a new object, and undo-ing the modification will delete the object.